- /* sffffdiv.cpp by K.Tsuru */
- // function ID = 713 DRADIX
- /*******************************
- SFraction class
- It provides the division "x/y".
- (x.num/x.den)/(y.num/y.den)=(x.num*y.den)/(x.den*y.num)
- ********************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- SFraction FFDiv(const SFraction& x, const SFraction& y){
- if(y.Sign(713) == 0) x.num.SetError(x.num.DIVIDED_BY_ZERO,"SF /", 713);
- SFraction z; // z.reduceDone = false;
- // if(&x == &y) z.SetLong(1, 1); // x/x
- if(x == y) z.SetLong(1, 1); // x/x since ver 2.30
- else if(x.Sign(713) == 0) z.SetZero();
- else {
- #if REDUCE_SIZE==0
- // z = (xn/xd)/(yn/yd) = (xn*yd)/(xd*yn)
- SLong d1 = gcdL(x.num, y.num), d2 = gcdL(x.den, y.den);
- z.num = (x.num/d1)*(y.den/d2); z.den = (x.den/d2)*(y.num/d1);
- z.reduceDone = true;
- #else
- if(x.ReduceStepByStep()) {
- SLong d1 = gcdL(x.num, y.num), d2 = gcdL(x.den, y.den);
- z.num = (x.num/d1)*(y.den/d2); z.den = (x.den/d2)*(y.num/d1);
- z.reduceDone = true;
- } else {
- z.num = x.num*y.den; z.den = x.den*y.num;
- z.reduce(false);
- }
- #endif
- }
- return z;
- }
sffffdiv.cpp : last modifiled at 2017/10/20 10:44:44(1,106 bytes)
created at 2015/12/22 16:07:29
The creation time of this html file is 2017/10/21 15:10:35 (Sat Oct 21 15:10:35 2017).